<?php 
include_once JPATH_ROOT . "/libraries/joomla/html/html/select.php";
JHTML::_('behavior.formvalidation'); 
?>
<script type="text/javascript">
function myValidate(form) {
	var error = '';
	var ok = true;
	for(i=0; i<form.elements.length; i++){
		if (! document.formvalidator.validate(form.elements[i])) {
			if( ok ) ok = false;

			switch(form.elements[i].name){
				case 'title':
						error += '<?=JText::_('NAME IS REQUIRED') ?>\n';
					break;
				case 'color':
						error += '<?=JText::_('COLOR IS REQUIRED') ?>\n';
					break;
			}
		}
	}
	if(error != '')
		alert(error);

	if(ok)
		form.check.value='<?php echo JUtility::getToken(); ?>';//send token

	return ok;
}

//Override the base function in folder: include/js/joomla.javascript.js
function submitbutton(pressbutton) {
	if(pressbutton.toUpperCase() != 'CANCEL'){
		if(myValidate(document.adminForm))
			submitform(pressbutton);
	}else{
		submitform(pressbutton)
	}
}
</script>
<form action="index.php" method="post" name="adminForm" id="adminForm" class="form-validate" onsubmit="return false">
<input type="hidden" name="check" value="post"/>
<div class="col100">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'Details' ); ?></legend>
		<table class="admintable"> 
		<tr>
			<td align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'SEND NOTIFY EMAIL' ); ?>:
				</label>
			</td>
			<td>
				<select name="send_notify_email" id="send_notify_email">
				<?php
					if ($this->settings->send_notify_email == 1){
				?>
					<option value="1" selected="selected"><?=JText::_("YES") ?></option>
					<option value="0"><?=JText::_("NO") ?></option>
				<?php					
					}else if ($this->settings->send_notify_email == 0) {
				?>
					<option value="0" selected="selected"><?=JText::_("NO") ?></option>
					<option value="1"><?=JText::_("YES") ?></option>
				<?php
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td  align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'SENDER ADDRESS' ); ?>:
				</label>
			</td>
			<td>
				<input type="text" name="sender_address" id="sender_address" size="30" value="<?=$this->settings->sender_address ?>">
			</td>
		</tr>
		<tr>
			<td align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'WEEK START ON' ); ?>:
				</label>
			</td>
			<td>
				<select name="week_start_on" id="week_start_on">
				<?php
				$arrDay = array(JText::_("MONDAY"),JText::_("TUESDAY"),JText::_("WEDNESDAY"),JText::_("THURSDAY"),JText::_("FRIDAY"),JText::_("SATURDAY"),JText::_("SUNDAY"));
				for($it = 0;$it<count($arrDay);$it++){
					$chk = ($this->settings->week_start_on == $it) ? "selected='selected'": "";					
					echo "<option value=\"".$it."\" ".$chk.">".$arrDay[$it]."</option>";
				}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td  align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'DEFAULT CALENDAR PAGE' ); ?>:
				</label>
			</td>
			<td>
				<select name="default_calendar_page" id="default_calendar_page">
				<?php
				$arr = array(JText::_("WEEK"),JText::_("MONTH"),JText::_("YEAR"));
				for($it = 0;$it<count($arr);$it++){
					$ch = ($this->settings->default_calendar_page == $it) ? "selected='selected'": "";					
					echo "<option value=\"".$it."\" ".$ch.">".$arr[$it]."</option>";
				}
				?>
				</select>
			</td>
		</tr>	
		<tr>
			<td  align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'TIME FORMAT' ); ?>:
				</label>
			</td>
			<td>
				<label for="muoihai">
				<input type="radio" name="time_format" id="muoihai" <?php if ($this->settings->time_format == 0) echo "checked=\"checked\"" ?> value="0">12h(am/pm)				
				</label>
				<br>
				<label for="">
				<input type="radio" name="time_format" id="haitu" <?php if ($this->settings->time_format == 1) echo "checked=\"checked\"" ?> value="1">24h				
				</label>
			</td>
		</tr>	
		<tr>
			<td  align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'THEME' ); ?>:
				</label>
			</td>
			<td>
				<select name="theme" id="theme">
				<?php
				//Get All files in a folder (Joomla 1.5)
				$themeCss 	= JFolder::files('../components/com_jbschedule/media/css/themes', '', true, false);

				$css 	= array( JHTMLSelect::option( '', 'Select image' ) );

				foreach( $themeCss AS $file ) {
					if( eregi( 'css', $file )) {
						$css[] = JHTMLSelect::option( $file );
						list($arr1,$arr2) = split('[.]',$file);	
						$checkTheme = ($this->settings->theme == $arr1) ? "selected=\"selected\"" : "" ;						
						echo "<option value=\"".$arr1."\" ".$checkTheme." >".strtolower($arr1)."</option>";
					}
				}	
				
				str_split(".");
				?>		
				</select>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<div class="clr"></div>
<input type="hidden" name="option" value="com_jbschedule" />
<input type="hidden" name="id" value="<?php echo $this->settings->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="settings" />
</form>
